package com.fzebu.fastboot.form;

import com.fzebu.fastboot.annotations.form.Browser;
import com.fzebu.fastboot.annotations.form.Number;
import com.fzebu.fastboot.annotations.form.Select;
import com.fzebu.fastboot.annotations.form.Text;
import com.fzebu.fastboot.form.parser.impl.BrowserTypeParser;
import com.fzebu.fastboot.form.parser.impl.NumberTypeParser;
import com.fzebu.fastboot.form.parser.impl.SelectTypeParser;
import com.fzebu.fastboot.form.parser.impl.TextTypeParser;

import java.lang.reflect.Field;

/**
 * @author Jack
 * @version 1.0.0
 * @create 2020/1/26 22:05
 */
public class TypeUtil {

    public static Object doParse(Field field, String alias, String value) {
        Object obj = value;
        if (field.isAnnotationPresent(Select.class)) {
            obj = new SelectTypeParser(field, alias, value).parse();
        } else if (field.isAnnotationPresent(Browser.class)) {
            obj = new BrowserTypeParser(field, alias, value).parse();
        } else if (field.isAnnotationPresent(Number.class)) {
            obj = new NumberTypeParser(field, alias, value).parse();
        } else if (field.isAnnotationPresent(Text.class)) {
            obj = new TextTypeParser(field, alias, value).parse();
        }
        return obj;
    }
}
